package com.myway.utils;

import java.io.StringReader;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

public class XmlUtil<T> {
	private Class<T> classType;
	public XmlUtil(Class<T> classType){
		this.classType=classType;
	}
	public <T> T xmlToObject(String str) {
		JAXBContext context = null;		
        T obj = null;
		try {
			context = JAXBContext.newInstance(classType);
			obj = (T)context.createUnmarshaller().unmarshal( new StringReader(str));
		} catch (JAXBException e) {
			e.printStackTrace();
		}
		return obj;
	}

}
